//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.wsd.smartcarwasher.controller;

import com.wsd.smartcarwasher.constans.ResultState;
import com.wsd.smartcarwasher.service.FileService;
import com.wsd.smartcarwasher.util.ReturnUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Api(
        tags = {"文件操作相关接口"}
)
@Controller
@CrossOrigin
public class FileController {
    private static final Logger logger = LoggerFactory.getLogger(FileController.class);
    @Resource
    private FileService fileService;

    public FileController() {
    }

    @ApiOperation(
            value = "文件上传",
            notes = "文件管理",
            response = ModelMap.class
    )
    @ApiImplicitParam(
            name = "file",
            value = "上传的文件",
            required = true,
            dataType = "MultipartFile"
    )
    @RequestMapping(
            value = {"/v1/file_upload"},
            method = {RequestMethod.POST},
            produces = {"application/json; charset=utf-8"}
    )
    @ResponseBody
    public ModelMap uploadFile(@RequestBody MultipartFile file) {
        return file.isEmpty() ? ReturnUtil.Error(ResultState.UPLOAD_FILE_IS_NULL.getMsg()) : this.fileService.uploadFile(file);
    }
}
